<!-- 搜索人员 -->
<template>
	<view class="">
		<view class="" @click="onClick">
			<u--input
			    :placeholder="placeholder"
				:placeholderClass="placeholderClass"
				:placeholderStyle="placeholderStyle"
				:inputAlign="inputAlign"
				:fontSize="fontSize"
				:color="color"
				:prefixIcon="prefixIcon"
				:prefixIconStyle="prefixIconStyle"
				:suffixIcon="suffixIcon"
				:suffixIconStyle="suffixIconStyle"
			    :border="border"
				:shape="shape"
				:customStyle="customStyle"
			    v-model="title"
				disabled
				:disabledColor="disabledColor"
			></u--input>
		</view>
	</view>
</template>

<script>
	import { erpmngUserId,erpmngUserIds } from '@/api/index.js'
	
	export default {
		data() {
			return {
				title:'', // 选中的标题名称
				isClick: false,
			}
		},
		model: {
			prop: 'value',
			event: 'change',
		},
		props: {
			// 编号（不知道啥玩意后台没有备注）
			commercialType: {
				type: [String,Number],
				default: ''
			},
			// 是否为多选 默认单选
			isMulti: {
				type: [Boolean],
				default: false
			},
			// 对象字段
			objectField: {
				type: [String],
				default: ' sicForm.yzdw'
			},
			// 是否禁用
			disabled: {
				type: Boolean,
				default: false
			},
			// 选中的值
			value: {
				type: [String, Number],
				default: '',
			},
			// 输入框为空时的占位符
			placeholder: {
				type: [String, Number],
				default: '请选择',
			},
			// 指定placeholder的样式类，注意页面或组件的style中写了scoped时，需要在类名前写/deep/
			placeholderClass: {
				type: [String],
				default: '',
			},
			// 指定placeholder的样式，字符串/对象形式，如"color: red;"
			placeholderStyle: {
				type: [String, Object],
				default: 'color: #C0C4CC'
			},
			// 输入框内容对齐方式 - left | center | right
			inputAlign: {
				type: [String],
				default: 'left',
			},
			// 输入框字体的大小
			fontSize: {
				type: [String, Number],
				default: '15px',
			},
			// 输入框字体颜色
			color: {
				type: [String],
				default: '#303133',
			},
			// 输入框前置图标
			prefixIcon: {
				type: [String],
				default: '',
			},
			// 前置图标样式，对象或字符串
			prefixIconStyle: {
				type: [String, Object],
				default: '',
			},
			// 输入框前置图标
			suffixIcon: {
				type: [String],
				default: '',
			},
			// 前置图标样式，对象或字符串
			suffixIconStyle: {
				type: [String, Object],
				default: '',
			},
			// 边框类型，surround-四周边框，bottom-底部边框，none-无边框
			border: {
				type: [String],
				default: 'surround',
			},
			// 输入框形状，circle-圆形，square-方形
			shape: {
				type: [String],
				default: 'square',
			},
			customStyle: {
				type: [Object],
				default: () => {},
			}
		},
		watch: {
			// 监听value是否有值
			value: {
				handler (val, oldVal) {
					if (val) {
						this.getPurchaseDetail()
					} else {
						this.title = ''
					}
					if (oldVal) {
						this.$emit('change',val);
					}
				},
				immediate: true
			},
		},
		computed: {
			// 当是disabled为true改变禁用的颜色
			disabledColor () {
				if (this.disabled) {
					return '#f5f7fa'
				} else {
					return '#FFFFFF'
				}
			}
		},
		methods: {
			// 获取详情
			getPurchaseDetail () {
				if (!this.value) {
					this.title = ''
					return false
				}
				var empIdArr = this.value.split(',')
				if (empIdArr.length == 1) {
					erpmngUserId({empId: this.value}).then(res => {
						if (res.success) {
							this.title = res.result.realname
							this.$emit('detail', res.result)
							if (this.isClick) {
								this.$emit('input', res.result)
								this.isClick = false
							}
						}
					})
				} else {
					erpmngUserIds({empId: this.value}).then(res => {
						if (res.success) {
							// this.title = res.result.realname
							this.$emit('detail', res.result)
							if (this.isClick) {
								this.$emit('input', res.result)
								this.isClick = false
							}
							var title = ''
							res.result.map(value => {
								title = value.realname + ',' + title
							})
							title = title.substring(0, title.lastIndexOf(','))
							this.title = title
						}
					})
				}
				
			},
			
			onClick () {
				if (this.disabled) {
					return false
				}
				this.isClick = true
				if (!this.value) {
					this.value = ''
				}
				uni.navigateTo({
					url: `/pages/common/selectPerson?id=${this.value}&objectField=${this.objectField}&isMulti=${this.isMulti}`
				})
			}
		},
		mounted() {
			//初始化数据
			// this.queryDictModelByCodes(this.dictName);
		},
	}
</script>

<style lang="scss" scoped>
	
</style>